package com.dd.cloud.user.task;

import com.dd.cloud.user.service.consule.IConsultSubscribeService;
import com.dd.cloud.user.service.doctor.IDoctorEquityService;
import com.dd.cloud.user.service.doctor.IDoctorUserService;
import com.dd.cloud.user.service.educationvisit.IPatientEducationVisitService;
import com.dd.cloud.user.service.phar.pharservice.HrPharService;
import com.dd.cloud.user.service.phar.pharservice.HstPharService;
import com.dd.cloud.user.service.phar.pharservice.YfPharService;
import com.dd.cloud.user.service.resource.IAdvertInfoService;
import com.dd.cloud.user.service.resource.ISpreadInfoService;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author zk
 */
@Component
@Slf4j
public class LimitTask {
    @Autowired
    private IDoctorUserService doctorUserService;
    @Autowired
    private YfPharService yfPharService;
    @Autowired
    private IConsultSubscribeService consultSubscribeService;
    @Autowired
    private HrPharService hrPharService;
    @Autowired
    private HstPharService hstPharService;
    @Autowired
    private IDoctorEquityService doctorEquityService;
    @Autowired
    private IPatientEducationVisitService patientEducationVisitService;
    @Autowired
    private ISpreadInfoService spreadInfoService;
    @Autowired
    private IAdvertInfoService advertInfoService;

    /**
     * 每天凌晨0点0分10秒处理医生认证失效
     */
    @Scheduled(cron = "10 0 0 * * ?")
    @SchedulerLock(name = "doctorAuthLapse", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void doctorAuthLapse() {
        log.info("定时器处理医生认证失效");
        doctorUserService.doctorAuthLapse();
    }

    /**
     * 每天凌晨0点0分15秒处理医生认证失效消息通知
     */
    @Scheduled(cron = "15 0 0 * * ?")
    @SchedulerLock(name = "doctorAuthLapseNewsNotice", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void doctorAuthLapseNewsNotice() {
        log.info("定时器处理医生认证失效消息通知");
        doctorUserService.doctorAuthLapseNewsNotice();
    }

    /**
     * 每30分钟处理一方制药状态流转
     */
    @Scheduled(cron = "0 0/30 * * * ?")
    @SchedulerLock(name = "presStatusRoamYf", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void presStatusRoamYf() {
        log.info("定时器处理一方制药状态流转");
        yfPharService.presStatusRoamYf();
    }

    /**
     * 每30分钟处理和顺堂处方状态流转
     */
    @Scheduled(cron = "0 0/30 * * * ?")
    @SchedulerLock(name = "presStatusRoamHst", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void presStatusRoamHst() {
        log.info("定时器处理和顺堂处方状态流转");
        hstPharService.presStatusRoamHst();
    }

    /**
     * 每30分钟处理华润制药制药状态流转
     */
    @Scheduled(cron = "0 0/30 * * * ?")
    @SchedulerLock(name = "presStatusRoamHr", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void presStatusRoamHr() {
        log.info("定时器处理华润制药状态流转");
        hrPharService.presStatusRoamHr();
    }

    /**
     * 定时器处理每天凌晨0点0分01秒处理预约自动超时
     */
    @Scheduled(cron = "1 0 0 * * ?")
    @SchedulerLock(name = "consultAutoFinish", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void consultAutoSubmitTimeout() {
        log.info("定时器处理每天凌晨0点0分01秒处理预约自动超时");
        consultSubscribeService.consultAutoSubmitTimeout();
    }

    /**
     * 定时器处理每天10点0分0秒处理慈善账号免费权益失效提醒
     */
    @Scheduled(cron = "0 0 10 * * ?")
    @SchedulerLock(name = "csAccountExpireRemindSms", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void csAccountExpireRemindSms() {
        log.info("定时器处理每天凌晨0点0分01秒处理慈善账号免费权益失效提醒");
        doctorEquityService.csAccountExpireRemindSms();
    }

    /**
     * 定时器处理每天9点0分0秒处理发送用药提醒
     */
    @Scheduled(cron = "0 0 9 * * ?")
    @SchedulerLock(name = "taskPatientDrugTip", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void taskPatientDrugTip() {
        log.info("定时器处理每天9点0分0秒处理发送用药提醒");
        patientEducationVisitService.taskPatientDrugTip();
    }

    /**
     * 定时器处理每天凌晨0点0分01秒处理医生认证状态
     */
    @Scheduled(cron = "1 0 0 * * ?")
    @SchedulerLock(name = "csDoctorAccountRemind", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void csDoctorAccountRemind() {
        log.info("定时器处理每天凌晨0点0分01秒处理医生认证状态");
        doctorEquityService.csDoctorAccountRemind();
    }

    /**
     * 定时器处理每天凌晨0点0分01秒处理
     * 定时任务修改开屏页面状态
     * 定时任务修改广告状态
     */
    @Scheduled(cron = "1 0 0 * * ?")
    @SchedulerLock(name = "taskUpdateStatus", lockAtLeastForString = "PT2M", lockAtMostForString = "PT10M")
    public void taskUpdateStatus() {
        spreadInfoService.taskUpdateStatus();
        advertInfoService.taskUpdateStatus();
    }
}
